package com.teach.servlet;

import com.teach.dao.CountryInfoDAO;
import com.teach.dao.impl.CountryInfoDAOImpl;
import com.teach.dto.MedalSearch;
import com.teach.service.MedalService;
import com.teach.service.impl.MedalServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <pre>
 * -
 * Author : J.L.Zhou
 * E-Mail : 2233875735@qq.com
 * Tel : 151 1104 7708
 * Date : 2022-05-13 11:37
 * Version : 1.0
 * Copyright 2022 jlzhou.top Inc. All rights reserved.
 * Warning: this content is only for internal circulation of the company.
 *          It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
@WebServlet("/country.let")
public class CountryServlet extends HttpServlet {

  private CountryInfoDAO dao = new CountryInfoDAOImpl();
  private MedalService service = new MedalServiceImpl();
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try{
      String countryCode = req.getParameter("countryCode");
      req.setAttribute("c", dao.selectById(countryCode));
      MedalSearch search = new MedalSearch();
      search.setRowMax(999);
      search.setCountryCode(countryCode);
      search.setMedalNum(1);
      req.setAttribute("list1", service.list(search));
      search.setMedalNum(2);
      req.setAttribute("list2", service.list(search));
      search.setMedalNum(3);
      req.setAttribute("list3", service.list(search));
      req.getRequestDispatcher("/country.jsp").forward(req,resp);
    }catch (Exception e){
      throw new ServletException("获取国家奖牌错误", e);
    }
  }
}
